app.controller('az13', function ($scope, $rootScope, $http, $interval, $compile, $state,$sce) {
    //DOA
    $scope.five = function () {
        /*if(!$scope.ocrConfigPage.name || !$scope.ocrConfigPage.model || !$scope.ocrConfigPage.nick || !$scope.ocrConfigPage.firmware
            || !$scope.ocrConfigPage.serialNumber || !$scope.ocrConfigPage.jetdirect || !$scope.ocrConfigPage.gateway){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "配置页信息需扫描"));
            return;
        }*/

        if(!$scope.ocrConfigPage.model || !$scope.ocrConfigPage.serialNumber || !$scope.ocrConfigPage.jetdirect){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "配置页*号内容为必填项"));
            return;
        }

        if(!$scope.ocrConfigPage.name){
            $scope.ocrConfigPage.name = "";
        }
        if(!$scope.ocrConfigPage.nick){
            $scope.ocrConfigPage.nick = "";
        }
        if(!$scope.ocrConfigPage.firmware){
            $scope.ocrConfigPage.firmware = "";
        }
        if(!$scope.ocrConfigPage.gateway){
            $scope.ocrConfigPage.gateway = "";
        }

        /*if(!$scope.ocrSupplyStatusPage.cyanDate || !$scope.ocrSupplyStatusPage.magentaDate || !$scope.ocrSupplyStatusPage.yellowDate || !$scope.ocrSupplyStatusPage.blackDate){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "状态页信息需扫描"));
            return;
        }*/

        if(!$scope.ocrSupplyStatusPage.blackDate){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "状态页信息需扫描"));
            return;
        }

        if(!$scope.ocrSupplyStatusPage.cyanDate){
            $scope.ocrSupplyStatusPage.cyanDate = "";
        }
        if(!$scope.ocrSupplyStatusPage.magentaDate){
            $scope.ocrSupplyStatusPage.magentaDate = "";
        }
        if(!$scope.ocrSupplyStatusPage.yellowDate){
            $scope.ocrSupplyStatusPage.yellowDate = "";
        }

        if($scope.ocrUsageInfoPage.length == 0){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页信息需扫描"));
            return;
        }
        /*for(var i=0;i<3;i++){
            var obj = $scope.ocrUsageInfoPage[i];
            if(!obj.other || !obj.monochrome || !obj.accent
                || !obj.generalOffice || !obj.totalMono || !obj.totalColor){
                $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页信息需扫描"));
                return;
            }
        }

        //判断数字
        for(var i=0;i<3;i++){
            var obj = $scope.ocrUsageInfoPage[i];
            if(!isNumber(obj.other) || !isNumber(obj.monochrome) || !isNumber(obj.accent)
                || !isNumber(obj.generalOffice) || !isNumber(obj.totalMono) || !isNumber(obj.totalColor)){
                $rootScope.tipPopups.show(($rootScope.tipMessage = "请更正用量信息页不为数字的值"));
                return;
            }
        }*/

        /*if(!$scope.blh.long || !$scope.blh.lat){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "请开启定位稍后再试！"));
            return;
        }*/

        for(var i=0;i<3;i++){
            var obj = $scope.ocrUsageInfoPage[i];
            if(!obj.other){
                obj.other = "0";
            }if(!obj.monochrome){
                obj.monochrome = "0";
            }if(!obj.accent){
                obj.accent = "0";
            }if(!obj.generalOffice){
                obj.generalOffice = "0";
            }if(!obj.totalMono){
                obj.totalMono = "0";
            }if(!obj.totalColor){
                obj.totalColor = "0";
            }

            obj.longitude = $scope.blh.long;
            obj.latitude = $scope.blh.lat;
        }
        if($scope.ocrConfigPage.serialNumber.toLowerCase() != $scope.serialNumber.toLowerCase()){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "配置页序列号不匹配"));
            return;
        }

        if($scope.ocrclickcount < 1){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "请点击用量信息页ocr识别进行扫描"));
            return;
        }


        localStorage.setItem("sdm-ocrConfigPage",JSON.stringify($scope.ocrConfigPage));
        localStorage.setItem("sdm-ocrSupplyStatusPage",JSON.stringify($scope.ocrSupplyStatusPage));
        localStorage.setItem("sdm-ocrUsageInfoPage",JSON.stringify($scope.ocrUsageInfoPage));
        five.params.caseId = $scope.caseId;
        five.params.customeBlhLong = $scope.customerLng;
        five.params.customeBlhLat = $scope.customerLat;
        $state.go(five.stateName);
    }

    //获得模板数据
    /*$scope.getOrders = function () {
        if(!$scope.caseNum){
            return;
        }
		var postData = {
            "productNum": $scope.caseNum
        };
        postHttp($http, 'installtionCase/getUsageTemplate', postData, function (res) {
            if (res.code === 0 && res.msg == "success") {
                $scope.usageTemplate = res.data;

                $scope.$applyAsync();
            } else {
                $rootScope.tipPopups.show(($scope.tipMessage = res.message));
            }
        });
    }*/
    $scope.updatePopups = new ShowPopups('.update-popups');

    $scope.updateValue = function (value,msg) {
        $scope.tempValue = null;
        var temp = '<input type="text" ng-model="'+value+'"/>';
        if(msg == "青色" || msg == "品红" || msg == "黄色" || msg == "黑色"){
            switch (msg){
                case "青色":
                    $scope.tempValue = 1;
                    break;
                case "品红":
                    $scope.tempValue = 2;
                    break;
                case "黄色":
                    $scope.tempValue = 3;
                    break;
                case "黑色":
                    $scope.tempValue = 4;
                    break;
            }
            temp = '<div style="border: 1px solid #ccc;height: 50px;width: 95%;font-size: 16px;line-height: 50px;z-index: 1;" ng-model="'+value+'" ng-click="showlay()"></div>';
        }

        $("#temp").html('');
        $($compile(temp)($scope)).appendTo($("#temp"));
        $(".pc").addClass("new-popups-content");
        $(".pt").addClass("new-title");
        $scope.confirmMessage = msg;

        $scope.updatePopups.show();
    }

    $scope.popupsCancel = function () {
        $(".pc").removeClass("new-popups-content");
        $(".pt").removeClass("new-title");
        $scope.updatePopups.close();
    }

    $scope.showlay = function (type) {
        var day = new Date();

        $(".weui-picker").css("display","block");
        weui.datePicker({
            start: new Date(1995,1,31),
            end: new Date(day.getFullYear(),(day.getMonth()),day.getDate()),
            onChange: function (result) {
                // console.log(result);
            },
            onConfirm: function (result) {
                if (result && result.length > 0) {
                    value = '';
                    for (var i in result) {
                        value += result[i].label;
                    }
                    var time = value;
                    time = time.replace(/[^(\\u4e00-\\u9fa5)]/g, '/');
                    time = time.substring(0, time.length-1);

                    switch ($scope.tempValue){
                        case 1:
                            $scope.ocrSupplyStatusPage.cyanDate = time;
                            break;
                        case 2:
                            $scope.ocrSupplyStatusPage.magentaDate = time;
                            break;
                        case 3:
                            $scope.ocrSupplyStatusPage.yellowDate = time;
                            break;
                        case 4:
                            $scope.ocrSupplyStatusPage.blackDate = time;
                            break;
                    }

                    $scope.$applyAsync();
                    $scope.popupsCancel();
                }
            },
            onClose:function(){
                $scope.popupsCancel();
            }
        });
    }


    //获得数据
    $scope.getOrders = function () {
        if(!$scope.caseId){
            return;
        }
        var postData = {};
        getHttp($http, 'installtionCase/get?caseId='+$scope.caseId, postData, function (res) {
            if (res.code === 0 && res.msg == "success") {
                var temp = JSON.parse(res.installtionCase.productInfo);
                if(temp){
                    $scope.serialNumber = temp[0].serial_number;
                }else{
                    $scope.serialNumber = "";
                }
                if(res.ocrConfigPage){
                    $scope.ocrConfigPage = res.ocrConfigPage;  //配置页数据
                }else{
                    $scope.ocrConfigPage = {};
                }

                if(localStorage.getItem("sdm-ocrConfigPage")){
                    $scope.ocrConfigPage = JSON.parse(localStorage.getItem("sdm-ocrConfigPage"));
                }

                $scope.$applyAsync();
            } else {
                //$rootScope.tipPopups.show(($rootScope.tipMessage = res.msg));
            }
        });
    }


    //根据地址获得经纬度
    function geocoderGetLocation() {
        var address= $scope.sdmAddress;
        AMap.plugin('AMap.Geocoder', function() {
            var geocoder = new AMap.Geocoder({
                // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
                // city: '重庆',
            });
           // 使用geocoder做地理/逆地理编码
            geocoder.getLocation(`${address}`, function(status, result) {
                if (status === 'complete' && result.info === 'OK') {
                    // result中对应详细地理坐标信息
                    var lat=result.geocodes[0].location.lat;
                    var lng=result.geocodes[0].location.lng;
                    $scope.customerLng = lng;
                    $scope.customerLat = lat;
                    console.log(lat,lng);
                }
            })
        })
    }

    $scope.blhResult = function (msg) {
        if(msg){
            var location = "";
            if(checkPhone('android')){
                location = JSON.parse(msg);
            }else if(checkPhone("iphone")){
                location = msg;
            }
            if(!location.long || !location.lat){
                $rootScope.tipPopups.show(($rootScope.tipMessage = "请开启定位稍后再试！"));
                // window.location.href = "index.html";
                return;
            }
            $scope.blh = location;
        }else{
            $rootScope.tipPopups.show(($rootScope.tipMessage = "请开启定位稍后再试！"));
            return;
        }

        // alert("-----"+JSON.stringify($scope.blh));
    }

    //检查gps是否打开
    $scope.checkGPS = function(){
        var flag = false;
        if(checkPhone('android')){
            flag = AndroidMethod.checkGps();
        }else if(checkPhone("iphone")){
            //flag = context.checkGps();
        }
        return flag;
    }

    //获得经纬度进行判断
    $scope.checkBlh = function (type) {
        //获得经纬度进行判断
       if(checkPhone('android')){
           var flag = $scope.checkGPS();
           if(!flag){
               $rootScope.tipPopups.show(($rootScope.tipMessage = "请开启定位稍后再试！"));
               return;
           }
           AndroidMethod.appBlh("sdmBlhResult");
       }else if(checkPhone("iphone")){
           window.webkit.messageHandlers.appBlh.postMessage("sdmBlhResult");
       }
       // alert(JSON.stringify($scope.blh));
       if(!$scope.blh){
           $rootScope.tipPopups.show(($rootScope.tipMessage = "暂未获取当前定位地址，请稍后再试！"));
           return;
       }

      /* var reqeustData = {
           "caseId": $scope.caseId,
           "longitude": $scope.blh.long,
           "latitude": $scope.blh.lat,
           "customerLongitude":$scope.customerLng,
           "customerLatitude":$scope.customerLat
       };
       postHttp($http, 'installtionCase/checkGPS', reqeustData, function (res) {
           if (res.msg === 'success') {
               //$scope.runScan(type);
           } else {
               //$rootScope.tipPopups.show(($rootScope.tipMessage = res.msg));
               //return;
           }
       });*/
    	$scope.runScan(type);
    }
    //执行app扫描
    $scope.runScan = function (type) {
        //执行ocr扫描
        $scope.type = type;
        var scantype = "sdmOcrResult";

        if(checkPhone('android')){
            AndroidMethod.ocr(scantype);
        }else if(checkPhone("iphone")){
			window.webkit.messageHandlers.ocr.postMessage(scantype);
        }
    }

    //扫描
    $scope.scanOCR = function (type) {
        $scope.ocrclickcount += 1;  //记录ocr识别按钮点击次数
        $scope.checkBlh(type);
    }

    function handleData(value,data) {
        if(!data || !data[0]){
            data = [];
            for(var i=0;i<3;i++){
                data[i] = "";
            }
        }
        for(var i=0;i<3;i++){
            if(!$scope.ocrUsageInfoPage[i]){
                $scope.ocrUsageInfoPage[i] = {};
            }
            if(value == "type"){
                $scope.ocrUsageInfoPage[i][value] = (i+1);
                continue;
            }
            var tempData = data[i];
            if(tempData && (tempData.indexOf(",") != -1)){
                tempData = tempData.replace(",","");
            }

            $scope.ocrUsageInfoPage[i][value] = tempData;

            if($scope.blh.long && $scope.blh.lat){
                $scope.ocrUsageInfoPage[i].longitude = $scope.blh.long;
                $scope.ocrUsageInfoPage[i].latitude = $scope.blh.lat;
            }else{
                $scope.ocrUsageInfoPage[i].longitude = "109.09";
                $scope.ocrUsageInfoPage[i].latitude = "109.09";
            }

            if(value == "other"){
                if(!$scope.ocrUsageInfoPage[i].other){
                    $scope.ocrUsageInfoPage[i].other = 0;
                }
            }
        }
        $scope.$applyAsync();
    }

    function rehanldeData() {
        for(var i=0;i<3;i++){
            var obj = $scope.ocrUsageInfoPage[i];
            if(obj.monochrome){
                obj.totalMono = "0";
            }else if(pvcolor[i]){
                obj.totalColor = "0";
            }
        }
    }

    //扫描结果
    $scope.scanResult = function (msg) {
		//document.getElementById('testinfo').style.display="block";
		//document.getElementById('testinfo').value=JSON.stringify(msg);
		
		console.log("=======",JSON.stringify(msg));
		
        var ocrtype = supportModel(msg);
		
		console.log("type = "+ $scope.type+"->"+ocrtype+"->"+$scope.scanModel);
        if(1==$scope.type || "1" == $scope.type){ //配置页
            $scope.ocrConfigPage.name = getOCRValue(msg, $scope.scanModel, '配置页-产品名称');
            $scope.ocrConfigPage.model = getOCRValue(msg, $scope.scanModel, '配置页-型号');
            $scope.ocrConfigPage.nick = getOCRValue(msg, $scope.scanModel, '配置页-昵称');
            $scope.ocrConfigPage.firmware = getOCRValue(msg, $scope.scanModel, '配置页-固件版本');
            $scope.ocrConfigPage.serialNumber = getOCRValue(msg, $scope.scanModel, '配置页-序列号');
            $scope.ocrConfigPage.jetdirect = getOCRValue(msg, $scope.scanModel, '配置页-嵌入式');
            $scope.ocrConfigPage.gateway = getOCRValue(msg, $scope.scanModel, '配置页-LDAP');
            // $scope.ocrConfigPage.longitude = "109.09";
            // $scope.ocrConfigPage.latitude = "109.09";

            if($scope.blh.long && $scope.blh.lat){
                $scope.ocrConfigPage.longitude = $scope.blh.long;
                $scope.ocrConfigPage.latitude = $scope.blh.lat;
            }else{
                $scope.ocrConfigPage.longitude = "109.09";
                $scope.ocrConfigPage.latitude = "109.09";
            }


            $scope.$applyAsync();
            localStorage.setItem("sdm-ocrConfigPage",JSON.stringify($scope.ocrConfigPage));


            // alert(JSON.stringify($scope.ocrConfigPage));

        }else if(2==$scope.type || "2" == $scope.type){//耗材状态
            $scope.ocrSupplyStatusPage.cyanDate = getOCRValue(msg, $scope.scanModel, '状态页-青色碳粉盒');
            $scope.ocrSupplyStatusPage.magentaDate = getOCRValue(msg, $scope.scanModel, '状态页-品红色碳粉盒');
            $scope.ocrSupplyStatusPage.yellowDate = getOCRValue(msg, $scope.scanModel, '状态页-黄色碳粉盒');
            $scope.ocrSupplyStatusPage.blackDate = getOCRValue(msg, $scope.scanModel, '状态页-黑色碳粉盒');
            $scope.$applyAsync();
            localStorage.setItem("sdm-ocrSupplyStatusPage",JSON.stringify($scope.ocrSupplyStatusPage));


            // alert(JSON.stringify($scope.ocrSupplyStatusPage));
        }else if(3==$scope.type || "3" == $scope.type){//用量信息页
            var monochrome = getOCRValue(msg, $scope.scanModel, '用量页-黑白');
            var monochromeAry = monochrome.split(";");
            handleData("monochrome",monochromeAry);
            var accent = getOCRValue(msg, $scope.scanModel, '用量页-强化');
            var accentAry = accent.split(";");
            handleData("accent",accentAry);
            var generalOffice = getOCRValue(msg, $scope.scanModel, '用量页-一般办公');
            var generalOfficeAry = generalOffice.split(";");
            handleData("generalOffice",generalOfficeAry);
            var totalMono = getOCRValue(msg, $scope.scanModel, '用量页-总数');
            var totalMonoAry = totalMono.split(";");
            $scope.pvtotal = totalMono.split(";");
            handleData("totalMono",totalMonoAry);
            var totalColor = getOCRValue(msg, $scope.scanModel, '用量页-色彩总数');
            var totalColorAry = totalColor.split(";");
            handleData("totalColor",totalColorAry);
            var other = getOCRValue(msg, $scope.scanModel, '用量页-其它');
            var otherAry = other.split(";");
            handleData("other",otherAry);
            handleData("type");


			// 打印
			var printCount = getOCRValue(msg, $scope.scanModel, '用量页-打印');
			// 复印
			var copyCount = getOCRValue(msg, $scope.scanModel, '用量页-复印');
			// 传真
			var faxCount = getOCRValue(msg, $scope.scanModel, '用量页-传真');
			
			if(!$scope.ocrUsageInfoPage[0].monochrome) $scope.ocrUsageInfoPage[0].monochrome = printCount;
			if(!$scope.ocrUsageInfoPage[1].monochrome) $scope.ocrUsageInfoPage[1].monochrome = copyCount;
			if(!$scope.ocrUsageInfoPage[2].monochrome) $scope.ocrUsageInfoPage[2].monochrome = faxCount;

            //新增总数和彩色
            var pvtotal = getOCRValue(msg, $scope.scanModel, '用量页-总数');
            $scope.pvtotal = pvtotal.split(";");
            
			//新增彩色
			var pvcolor = getOCRValue(msg, $scope.scanModel, '用量页-彩色');
            $scope.pvcolor = pvcolor.split(";");
            var color = getOCRValue(msg, $scope.scanModel, '用量页-彩色');
            $scope.colorAry = color.split(";");
            rehanldeData();

			console.log("ocrtype=",ocrtype);

            switch(ocrtype){
                case 1:
                    $scope.ocrUsageInfoPage[0].monochrome = 0;
                    $scope.ocrUsageInfoPage[0].accent = 0;
                    $scope.ocrUsageInfoPage[0].generalOffice = 0;
                    $scope.ocrUsageInfoPage[0].totalColor = 0;
                    $scope.ocrUsageInfoPage[0].other = 0;
                    $scope.ocrUsageInfoPage[0].totalMono=$scope.pvtotal[0];
                    $scope.ocrUsageInfoPage[1].monochrome = 0;
                    $scope.ocrUsageInfoPage[1].accent = 0;
                    $scope.ocrUsageInfoPage[1].generalOffice = 0;
                    $scope.ocrUsageInfoPage[1].totalMono = 0;
                    $scope.ocrUsageInfoPage[1].totalColor = 0;
                    $scope.ocrUsageInfoPage[1].other = 0;
                    $scope.ocrUsageInfoPage[2].monochrome = 0;
                    $scope.ocrUsageInfoPage[2].accent = 0;
                    $scope.ocrUsageInfoPage[2].generalOffice = 0;
                    $scope.ocrUsageInfoPage[2].totalMono = 0;
                    $scope.ocrUsageInfoPage[2].totalColor = 0;
                    $scope.ocrUsageInfoPage[2].other = 0;
                    break;
                case 2:
                    $scope.ocrUsageInfoPage[0].totalMono = $scope.ocrUsageInfoPage[0].monochrome;
                    $scope.ocrUsageInfoPage[0].totalColor = $scope.colorAry[0];
                    $scope.ocrUsageInfoPage[0].monochrome = 0;
                    $scope.ocrUsageInfoPage[0].accent = 0;
                    $scope.ocrUsageInfoPage[0].generalOffice = 0;
                    $scope.ocrUsageInfoPage[0].other = 0;
                    $scope.ocrUsageInfoPage[1].monochrome = 0;
                    $scope.ocrUsageInfoPage[1].accent = 0;
                    $scope.ocrUsageInfoPage[1].generalOffice = 0;
                    $scope.ocrUsageInfoPage[1].totalMono = 0;
                    $scope.ocrUsageInfoPage[1].totalColor = 0;
                    $scope.ocrUsageInfoPage[1].other = 0;
                    $scope.ocrUsageInfoPage[2].monochrome = 0;
                    $scope.ocrUsageInfoPage[2].accent = 0;
                    $scope.ocrUsageInfoPage[2].generalOffice = 0;
                    $scope.ocrUsageInfoPage[2].totalMono = 0;
                    $scope.ocrUsageInfoPage[2].totalColor = 0;
                    $scope.ocrUsageInfoPage[2].other = 0;
                    break;
                case 3:
                    $scope.ocrUsageInfoPage[0].totalMono = 0;
                    $scope.ocrUsageInfoPage[0].totalColor = 0;
                    $scope.ocrUsageInfoPage[1].monochrome = 0;
                    $scope.ocrUsageInfoPage[1].accent = 0;
                    $scope.ocrUsageInfoPage[1].generalOffice = 0;
                    $scope.ocrUsageInfoPage[1].totalMono = 0;
                    $scope.ocrUsageInfoPage[1].totalColor = 0;
                    $scope.ocrUsageInfoPage[1].other = 0;
                    $scope.ocrUsageInfoPage[2].monochrome = 0;
                    $scope.ocrUsageInfoPage[2].accent = 0;
                    $scope.ocrUsageInfoPage[2].generalOffice = 0;
                    $scope.ocrUsageInfoPage[2].totalMono = 0;
                    $scope.ocrUsageInfoPage[2].totalColor = 0;
                    $scope.ocrUsageInfoPage[2].other = 0;
                    break;
                case 4:
                    $scope.ocrUsageInfoPage[0].monochrome = 0;
                    $scope.ocrUsageInfoPage[0].accent = 0;
                    $scope.ocrUsageInfoPage[0].generalOffice = 0;
                    $scope.ocrUsageInfoPage[0].totalColor = 0;
                    $scope.ocrUsageInfoPage[0].other = 0;
                    $scope.ocrUsageInfoPage[0].totalMono=$scope.pvtotal[0];
                    $scope.ocrUsageInfoPage[1].monochrome = 0;
                    $scope.ocrUsageInfoPage[1].accent = 0;
                    $scope.ocrUsageInfoPage[1].generalOffice = 0;
                    $scope.ocrUsageInfoPage[1].totalMono=$scope.pvtotal[1];
                    $scope.ocrUsageInfoPage[1].totalColor = 0;
                    $scope.ocrUsageInfoPage[1].other = 0;
					$scope.ocrUsageInfoPage[2].monochrome = 0;
                    $scope.ocrUsageInfoPage[2].accent = 0;
                    $scope.ocrUsageInfoPage[2].generalOffice = 0;
                    $scope.ocrUsageInfoPage[2].totalMono = $scope.pvtotal[2];
                    $scope.ocrUsageInfoPage[2].totalColor = 0;
                    $scope.ocrUsageInfoPage[2].other = 0;
                    break;
                case 5:
                    $scope.ocrUsageInfoPage[0].totalMono = $scope.ocrUsageInfoPage[0].monochrome;
                    $scope.ocrUsageInfoPage[0].totalColor = $scope.colorAry[0];
                    $scope.ocrUsageInfoPage[0].monochrome = 0;
                    $scope.ocrUsageInfoPage[0].accent = 0;
                    $scope.ocrUsageInfoPage[0].generalOffice = 0;
                    $scope.ocrUsageInfoPage[0].other = 0;
                    $scope.ocrUsageInfoPage[1].totalMono = $scope.ocrUsageInfoPage[1].monochrome;
                    $scope.ocrUsageInfoPage[1].totalColor = $scope.colorAry[1];
                    $scope.ocrUsageInfoPage[1].monochrome = 0;
                    $scope.ocrUsageInfoPage[1].accent = 0;
                    $scope.ocrUsageInfoPage[1].generalOffice = 0;
                    $scope.ocrUsageInfoPage[1].other = 0;
                    $scope.ocrUsageInfoPage[2].totalMono = $scope.ocrUsageInfoPage[2].monochrome;
                    $scope.ocrUsageInfoPage[2].totalColor = $scope.colorAry[2];
                    $scope.ocrUsageInfoPage[2].monochrome = 0;
                    $scope.ocrUsageInfoPage[2].accent = 0;
                    $scope.ocrUsageInfoPage[2].generalOffice = 0;
                    $scope.ocrUsageInfoPage[2].other = 0;
                    break;
                case 6:
                    $scope.ocrUsageInfoPage[0].totalMono = 0;
                    $scope.ocrUsageInfoPage[0].totalColor = 0;
                    $scope.ocrUsageInfoPage[1].totalMono = 0;
                    $scope.ocrUsageInfoPage[1].totalColor = 0;
                    $scope.ocrUsageInfoPage[2].totalMono = 0;
                    $scope.ocrUsageInfoPage[2].totalColor = 0;
                    break;
            }

            console.log("---",JSON.stringify($scope.ocrUsageInfoPage));
            $scope.$applyAsync();
            localStorage.setItem("sdm-ocrUsageInfoPage",JSON.stringify($scope.ocrUsageInfoPage));

            // alert(JSON.stringify($scope.ocrUsageInfoPage));
        }
    }


    function supportModel(msg){
        getOCRValue(msg, $scope.scanModel, '用量页-黑白');
        return typeModel;
    }


    //提交数据
    $scope.submit = function () {
        if(!$scope.caseId){
            return;
        }
        $scope.ocrStatusReportPage = {};
        $scope.ocrConfigPage1 = {};
        $scope.ocrConfigPage1.name = $scope.ocrConfigPage.name;
        $scope.ocrConfigPage1.nick = $scope.ocrConfigPage.nick;
        $scope.ocrConfigPage1.model = $scope.ocrConfigPage.model;
        $scope.ocrConfigPage1.firmware = $scope.ocrConfigPage.firmware;
        $scope.ocrConfigPage1.serialNumber = $scope.ocrConfigPage.serialNumber;
        $scope.ocrConfigPage1.jetdirect = $scope.ocrConfigPage.jetdirect;
        $scope.ocrConfigPage1.gateway = $scope.ocrConfigPage.gateway;
        $scope.ocrConfigPage1.longitude = $scope.ocrConfigPage.longitude;
        $scope.ocrConfigPage1.latitude = $scope.ocrConfigPage.latitude;

        $scope.ocrSupplyStatusPage1 = {};
        $scope.ocrSupplyStatusPage1.cyanDate = $scope.ocrSupplyStatusPage.cyanDate;
        $scope.ocrSupplyStatusPage1.magentaDate = $scope.ocrSupplyStatusPage.magentaDate;
        $scope.ocrSupplyStatusPage1.yellowDate = $scope.ocrSupplyStatusPage.yellowDate;
        $scope.ocrSupplyStatusPage1.blackDate = $scope.ocrSupplyStatusPage.blackDate;

        $scope.ocrUsageInfoPage1=[];
        $scope.ocrUsageInfoPage1[0]={};
        $scope.ocrUsageInfoPage1[1]={};
        $scope.ocrUsageInfoPage1[2]={};

        $scope.ocrUsageInfoPage1[0].type = $scope.ocrUsageInfoPage[0].type;
        $scope.ocrUsageInfoPage1[0].monochrome = $scope.ocrUsageInfoPage[0].monochrome;
        $scope.ocrUsageInfoPage1[0].accent = $scope.ocrUsageInfoPage[0].accent;
        $scope.ocrUsageInfoPage1[0].generalOffice = $scope.ocrUsageInfoPage[0].generalOffice;
        $scope.ocrUsageInfoPage1[0].other = $scope.ocrUsageInfoPage[0].other;
        $scope.ocrUsageInfoPage1[0].totalMono = $scope.ocrUsageInfoPage[0].totalMono;
        $scope.ocrUsageInfoPage1[0].totalColor = $scope.ocrUsageInfoPage[0].totalColor;
        $scope.ocrUsageInfoPage1[0].longitude = $scope.ocrUsageInfoPage[0].longitude;
        $scope.ocrUsageInfoPage1[0].latitude = $scope.ocrUsageInfoPage[0].latitude;

        $scope.ocrUsageInfoPage1[1].type = $scope.ocrUsageInfoPage[1].type;
        $scope.ocrUsageInfoPage1[1].monochrome = $scope.ocrUsageInfoPage[1].monochrome;
        $scope.ocrUsageInfoPage1[1].accent = $scope.ocrUsageInfoPage[1].accent;
        $scope.ocrUsageInfoPage1[1].generalOffice = $scope.ocrUsageInfoPage[1].generalOffice;
        $scope.ocrUsageInfoPage1[1].other = $scope.ocrUsageInfoPage[1].other;
        $scope.ocrUsageInfoPage1[1].totalMono = $scope.ocrUsageInfoPage[1].totalMono;
        $scope.ocrUsageInfoPage1[1].totalColor = $scope.ocrUsageInfoPage[1].totalColor;
        $scope.ocrUsageInfoPage1[1].longitude = $scope.ocrUsageInfoPage[1].longitude;
        $scope.ocrUsageInfoPage1[1].latitude = $scope.ocrUsageInfoPage[1].latitude;

        $scope.ocrUsageInfoPage1[2].type = $scope.ocrUsageInfoPage[2].type;
        $scope.ocrUsageInfoPage1[2].monochrome = $scope.ocrUsageInfoPage[2].monochrome;
        $scope.ocrUsageInfoPage1[2].accent = $scope.ocrUsageInfoPage[2].accent;
        $scope.ocrUsageInfoPage1[2].generalOffice = $scope.ocrUsageInfoPage[2].generalOffice;
        $scope.ocrUsageInfoPage1[2].other = $scope.ocrUsageInfoPage[2].other;
        $scope.ocrUsageInfoPage1[2].totalMono = $scope.ocrUsageInfoPage[2].totalMono;
        $scope.ocrUsageInfoPage1[2].totalColor = $scope.ocrUsageInfoPage[2].totalColor;
        $scope.ocrUsageInfoPage1[2].longitude = $scope.ocrUsageInfoPage[2].longitude;
        $scope.ocrUsageInfoPage1[2].latitude = $scope.ocrUsageInfoPage[2].latitude;

        var postData = {
            "caseId": $scope.caseId,
            "ocrConfigPage": $scope.ocrConfigPage1,
            "ocrStatusReportPage": $scope.ocrStatusReportPage,
            "ocrSupplyStatusPage": $scope.ocrSupplyStatusPage1,
            "ocrUsageInfoPage": $scope.ocrUsageInfoPage1
        };

        postData.imageUrls = [];
        postData.feSignUrl = "";
        postData.customerSignUrl = "";

        console.log(postData);

        $scope.result = JSON.stringify(postData);

        // alert(JSON.stringify(postData));

        postHttp($http, 'installtionCase/commitOcrDetail', postData, function (res) {
            if (res.code === 0 && res.msg == "success") {
                // alert(0);
                $scope.five();
                $scope.$applyAsync();
            } else {
                // alert(res.msg);
                $rootScope.tipPopups.show(($scope.tipMessage = res.msg));
            }
        });

    };
    //清除storage数据
    $scope.removeStorge = function () {
        var token = getToken();
        //localStorage.clear();
        hpclearCache();
        sessionStorage.setItem("token", token);
    }

    //初始化
    function init(){
        //定位
        $scope.blh = {
            long:"",
            lat:""
        };
        //ocr点击次数
        $scope.ocrclickcount = 0;
        //案例caseNum
        $scope.caseNum = az13.params.caseNum;
        if(!az13.params.caseNum){
            $scope.caseNum = localStorage.getItem("sdm-caseNum");
        }
        $scope.caseId = az13.params.caseId;
        if(!az13.params.caseId){
            $scope.caseId = localStorage.getItem("sdm-caseId");
        }
        $scope.sdmAddress = az13.params.address;
        $scope.productName = az13.params.productName;

        geocoderGetLocation();
        $scope.ocrConfigPage = {};
        $scope.ocrUsageInfoPage = [];
        $scope.ocrSupplyStatusPage = {};
        $scope.scanModel = $scope.productName;   //扫描型号
        //获得模板
        $scope.getOrders();

        if(localStorage.getItem("sdm-ocrUsageInfoPage")){
            $scope.ocrUsageInfoPage = JSON.parse(localStorage.getItem("sdm-ocrUsageInfoPage"));
        }
        if(localStorage.getItem("sdm-ocrSupplyStatusPage")){
            $scope.ocrSupplyStatusPage = JSON.parse(localStorage.getItem("sdm-ocrSupplyStatusPage"));
        }


        /*
         var data = {"words_result_num":51,"log_id":5533774432326921782,"words_result":[{"words":"设备信息"},{"words":"产品名称:HPPageWideColorMFPP77940"},{"words":"昵称:HPPageWideColorMFPP777940"},{"words":"型号:Y3Z61A"},{"words":"英文固件版本:B2P1N0021902G00"},{"words":"产品序列号:MYBPM669003"},{"words":"格式化板号码:9C20CL7"},{"words":"cB:3.395"},{"words":"SCB:XXXXFA1848BR1.0"},{"words":"固件捆绑包版本:4.7.1.3"},{"words":"固件版本:2407166000464"},{"words":"期代码:20190420"},{"words":"固件日期代码"},{"words":"HPFutureSmart级别:HPFutureSmart4"},{"words":"NFC版本:未安装"},{"words":"服务ID:00000"},{"words":"文档进纸器套件间隔时间:50000"},{"words":"自上次执行文档进纸器维护后的页数:0"},{"words":"PS等待超时:300秒"},{"words":"引擎周期*:0"},{"words":"彩色引擎周期*:0"},{"words":"碳粉盒保护:关"},{"words":"碳粉盒指标:IKPFCLEG"},{"words":"产品区域:10"},{"words":"*不适用于计费"},{"words":"安装的个性和选件"},{"words":"PCL:20010402"},{"words":"PCLXL:20010402"},{"words":"POSTSCRIPT:20010402"},{"words":"PDF:20130901"},{"words":"AirPrint:2040201"},{"words":"PWGRASTER:2040201"},{"words":"tF:20150522"},{"words":"内部磁盘:硬盘:已启用"},{"words":"序列号:5BD0520B"},{"words":"型号:Toshiba07G610"},{"words":"容量:15028MB"},{"words":"硬盘加密状态:无法加密磁盘"},{"words":"TPM:已启用"},{"words":"固件:149.33"},{"words":"EK指纹:"},{"words":"187523A91082ADE71FBB54259A54232AA6AEA4B"},{"words":"SRK指纹:"},{"words":"0C276D613AC508F7B385DEB41B495AE115DBABDD"},{"words":"嵌入式JetDirect页:192.168.99.38"},{"words":"LDAP网关:0.0.0.0"},{"words":"高级数字发送"},{"words":"自定义颜色表:未安装"},{"words":"HPWeb服务"},{"words":"HPWeb服务:已禁用"},{"words":"ePrint:已禁用"}]};

        $scope.scanResult(data,1);
        $scope.ocrSupplyStatusPage = {};
        $scope.ocrSupplyStatusPage.cyanDate = "20190709";
        $scope.ocrSupplyStatusPage.magentaDate = "20190709";
        $scope.ocrSupplyStatusPage.yellowDate = "20190709";
        $scope.ocrSupplyStatusPage.blackDate = "20190709";

        var data2 = {
            "log_id" : 3650753902062636342,
            "words_result" : [ {
                "words" : "等效印数(Letter\/A4)"
            }, {
                "words" : "彩色"
            }, {
                "words" : "黑白强化一般办公其它色彩总数总数"
            }, {
                "words" : "打印"
            }, {
                "words" : "0.0"
            }, {
                "words" : "0.0"
            }, {
                "words" : "0.00.0"
            }, {
                "words" : "0.00.0"
            }, {
                "words" : "复印"
            }, {
                "words" : "0.0"
            }, {
                "words" : "0.0"
            }, {
                "words" : "0.00.0"
            }, {
                "words" : "0.00.0"
            }, {
                "words" : "传真"
            }, {
                "words" : "0.0"
            }, {
                "words" : "*"
            }, {
                "words" : "0.0"
            }, {
                "words" : "0.00.0"
            }, {
                "words" : "0.00.0"
            } ],
            "words_result_num" : 19
        }
        $scope.scanResult(data2,3);*/
    }
    
    init();

    reloadJs();
});
//返回扫描结果
function sdmOcrResult(msg) {
    var $scope = getScope("az13");
    if(checkPhone('android')){
        msg = JSON.parse(msg);
    }
    $scope.scanResult(msg);
}
function sdmBlhResult(msg) {
    var $scope = getScope("az13");
    $scope.blhResult(msg);
}